/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "sle_hdi_test_entry.h"
#include "sle_adapter_hdi.h"
#include "sle_error_code.h"
#include "sle_unit_test_log.h"

static SleHdiOpts* g_sleHdiUtOpts = NULL;

void SleInitOptsTestLevel0(void)
{
    SleHdiErrorCode ret = SleHdiInitOpts(g_sleHdiUtOpts);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_NO_ERROR, "[SleAdapterTest][FAILED]SleInitOptsTestLevel0 failed(%d)", ret);
    SLE_UT_CHECK_AND_PRINT_LOG(g_sleHdiUtOpts->hostOpts != NULL, "[SleAdapterTest][FAILED]SleInitOptsTestLevel0 failed(hostOpts)");
    SLE_UT_CHECK_AND_PRINT_LOG(g_sleHdiUtOpts->seekOpts != NULL, "[SleAdapterTest][FAILED]SleInitOptsTestLevel0 failed(seekOpts)");
    SLE_UT_CHECK_AND_PRINT_LOG(g_sleHdiUtOpts->announceOpts != NULL, "[SleAdapterTest][FAILED]SleInitOptsTestLevel0 failed(announceOpts)");
    SLE_UT_CHECK_AND_PRINT_LOG(g_sleHdiUtOpts->connectOpts != NULL, "[SleAdapterTest][FAILED]SleInitOptsTestLevel0 failed(connectOpts)");
    SLE_UT_CHECK_AND_PRINT_LOG(g_sleHdiUtOpts->ssapcOpts != NULL, "[SleAdapterTest][FAILED]SleInitOptsTestLevel0 failed(ssapcOpts)");
    SLE_UT_CHECK_AND_PRINT_LOG(g_sleHdiUtOpts->ssapsOpts != NULL, "[SleAdapterTest][FAILED]SleInitOptsTestLevel0 failed(ssapsOpts)");
}

void SleAdapterHdiTestEntryTestLevel0(void)
{
    SleInitOptsTestLevel0();
}

SleHdiErrorCode InitSleAdapterHdiTestEntry(void)
{
    g_sleHdiUtOpts = (SleHdiOpts*)malloc(sizeof(SleHdiOpts));
    g_sleHdiUtOpts->hostOpts = (SleHostHdiOpts*)malloc(sizeof(SleHostHdiOpts));
    g_sleHdiUtOpts->announceOpts = (SleAnnounceHdiOpts*)malloc(sizeof(SleAnnounceHdiOpts));
    g_sleHdiUtOpts->seekOpts = (SleSeekHdiOpts*)malloc(sizeof(SleSeekHdiOpts));
    g_sleHdiUtOpts->connectOpts = (SleConnectHdiOpts*)malloc(sizeof(SleConnectHdiOpts));
    g_sleHdiUtOpts->ssapcOpts = (SleSsapcHdiOpts*)malloc(sizeof(SleSsapcHdiOpts));
    g_sleHdiUtOpts->ssapsOpts = (SleSsapsHdiOpts*)malloc(sizeof(SleSsapsHdiOpts));
    return SLE_HDI_ERRCODE_SUCC;
}

SleHdiErrorCode DeinitSleAdapterHdiTestEntry(void)
{
    free(g_sleHdiUtOpts->hostOpts);
    free(g_sleHdiUtOpts->announceOpts);
    free(g_sleHdiUtOpts->seekOpts);
    free(g_sleHdiUtOpts->connectOpts);
    free(g_sleHdiUtOpts->ssapcOpts);
    free(g_sleHdiUtOpts->ssapsOpts);
    free(g_sleHdiUtOpts);
    return SLE_HDI_ERRCODE_SUCC;
}

void SleAdapterHdiTestEntry(void)
{
    SLE_UT_LOG("__SleAdapterHdiTestEntry start\n");
    SleHdiErrorCode ret = SLE_HDI_ERRCODE_FAIL;
    ret = InitSleAdapterHdiTestEntry();
    SLE_UT_CHECK_AND_RETURN(ret == SLE_HDI_ERRCODE_SUCC);
    SleAdapterHdiTestEntryTestLevel0();
    ret = DeinitSleAdapterHdiTestEntry();
    SLE_UT_CHECK_AND_RETURN(ret == SLE_HDI_ERRCODE_SUCC);
    SLE_UT_LOG("__SleAdapterHdiTestEntry end\n");
}